package com.unisound.tracelog.server.clear;

import com.unisound.tracelog.common.annotation.log.Log;
import com.unisound.tracelog.server.service.TraceLogService;
import com.unisound.tracelog.server.service.TraceLogTagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 只保留最近两周的span
 */
@Slf4j
@Component
public class ClearExpiredSpan {

    @Autowired
    private TraceLogService traceLogService;

    @Autowired
    private TraceLogTagService traceLogTagService;

    @Log("清理过期数据")
    @Scheduled(cron = "0 0 4 * * ?")
    public void clearExpiredSpan() {
        traceLogTagService.clearExpiredSpan();
        traceLogService.clearExpiredSpan();
    }

}
